package com.ruoyi.sales.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sales.domain.ZcPlanCode;
import com.ruoyi.sales.service.IZcPlanCodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计划编码Controller
 * 
 * @author woo
 * @date 2024-03-22
 */
@RestController
@RequestMapping("/sales/code")
public class ZcPlanCodeController extends BaseController
{
    @Autowired
    private IZcPlanCodeService zcPlanCodeService;

    /**
     * 查询计划编码列表
     */
    @PreAuthorize("@ss.hasPermi('sales:code:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZcPlanCode zcPlanCode)
    {
        startPage();
        List<ZcPlanCode> list = zcPlanCodeService.selectZcPlanCodeList(zcPlanCode);
        return getDataTable(list);
    }

    /**
     * 导出计划编码列表
     */
    @PreAuthorize("@ss.hasPermi('sales:code:export')")
    @Log(title = "计划编码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZcPlanCode zcPlanCode)
    {
        List<ZcPlanCode> list = zcPlanCodeService.selectZcPlanCodeList(zcPlanCode);
        ExcelUtil<ZcPlanCode> util = new ExcelUtil<ZcPlanCode>(ZcPlanCode.class);
        util.exportExcel(response, list, "计划编码数据");
    }

    /**
     * 获取计划编码详细信息
     */
    @PreAuthorize("@ss.hasPermi('sales:code:query')")
    @GetMapping(value = "/{codeId}")
    public AjaxResult getInfo(@PathVariable("codeId") Long codeId)
    {
        return success(zcPlanCodeService.selectZcPlanCodeByCodeId(codeId));
    }

    /**
     * 新增计划编码
     */
    @PreAuthorize("@ss.hasPermi('sales:code:add')")
    @Log(title = "计划编码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZcPlanCode zcPlanCode)
    {
        return toAjax(zcPlanCodeService.insertZcPlanCode(zcPlanCode));
    }

    /**
     * 修改计划编码
     */
    @PreAuthorize("@ss.hasPermi('sales:code:edit')")
    @Log(title = "计划编码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZcPlanCode zcPlanCode)
    {
        return toAjax(zcPlanCodeService.updateZcPlanCode(zcPlanCode));
    }

    /**
     * 删除计划编码
     */
    @PreAuthorize("@ss.hasPermi('sales:code:remove')")
    @Log(title = "计划编码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codeIds}")
    public AjaxResult remove(@PathVariable Long[] codeIds)
    {

        return toAjax(zcPlanCodeService.deleteZcPlanCodeByCodeIds(codeIds));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('sales:code:edit')")
    @Log(title = "计划编码", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody ZcPlanCode planCode)
    {
        return toAjax(zcPlanCodeService.updateCodeStatus(planCode));
    }
}
